from Crypto.Cipher import AES
from Crypto.Util.Padding import pad, unpad
import base64

def aes_encrypt(text, key):
    key = key.encode('utf-8')
    cipher = AES.new(key, AES.MODE_ECB)
    text_bytes = text.encode('utf-8')
    padded_text = pad(text_bytes, AES.block_size)
    encrypted_bytes = cipher.encrypt(padded_text)
    encrypted_text = base64.b64encode(encrypted_bytes).decode('utf-8')
    return encrypted_text

def aes_decrypt(text, key):
    key = key.encode('utf-8')
    cipher = AES.new(key, AES.MODE_ECB)
    encrypted_bytes = base64.b64decode(text)
    decrypted_bytes = cipher.decrypt(encrypted_bytes)
    unpadded_bytes = unpad(decrypted_bytes, AES.block_size)
    decrypted_text = unpadded_bytes.decode('utf-8')
    return decrypted_text

def aes_encrypt_binary(data, key):
    key = key.encode('utf-8')
    cipher = AES.new(key, AES.MODE_ECB)
    padded_data = pad(data, AES.block_size)
    encrypted_data = cipher.encrypt(padded_data)
    return encrypted_data

def aes_decrypt_binary(data, key):
    key = key.encode('utf-8')
    cipher = AES.new(key, AES.MODE_ECB)
    decrypted_data = cipher.decrypt(data)
    unpadded_data = unpad(decrypted_data, AES.block_size)
    return unpadded_data